home *** CD-ROM | disk | FTP | other *** search
/ The Essential Home & Business Collection / The Essential Home & Business Collection.iso / 27 / 3 / 5 / HP22D5.ZIP / EXTERN / MONTH.C < prev    next >
Text File  |  1991-04-16  |  1KB  |  67 lines

  1. #include "extern.h"        /* Extensions need these! */
  2.  
  3. BYTE near months[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  4.  
  5. /*
  6. ** This routine creates a month.
  7. **
  8. ** Parameters:
  9. **
  10. **    month        which month to display
  11. **    year        which year to display
  12. **    startday    starting day in that month
  13. **            (use convert to figure this out)
  14. **
  15. ** To call this function from HyperPAD:
  16. **
  17. **    get 1990,1,1,0,0,0,0;          -- assemble a dateItem list
  18. **    convert it to dateItems;       -- normalize (figure out 1st day)
  19. **    put makeMonth(1990,1,item 7 of it) into page field 1;
  20. */
  21. MakeMonth(int NumArgs,HANDLE hMonth,HANDLE hYear,HANDLE hStartDay)
  22.  
  23. {
  24.     register int i,j;
  25.     int year,month,numdays,startday;
  26.     PTR p,buf;
  27.  
  28.     buf = NewPtr(200);
  29.  
  30.     month = htoi(hMonth) - 1;
  31.     year = htoi(hYear);
  32.     startday = htoi(hStartDay) - 1;
  33.  
  34.     numdays = (month == 1) ? (year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ? 29 : 28) : months[month];
  35.  
  36.     p = buf;
  37.     for (i=0;i<startday;i++) {
  38.         for (j=0;j<4;j++) *p++ = ' ';
  39.     }
  40.  
  41.     for (j=1;j<=numdays;j++,i++) {
  42.         if (i >= 7) {
  43.         *p++ = '\r';
  44.         i = 0;
  45.         }
  46.         sprintf(p,"%3d ",j);
  47.         p += 4;
  48.     }
  49.     *p = '\0';
  50.  
  51.     ReturnValue(stoh(buf));
  52.     FreePtr(buf);
  53.     return(STOP);
  54. }
  55.  
  56. POOL pascal Pool[] = {
  57.     {    "MakeMonth",        /* name of the handler */
  58.         MakeMonth,        /* pointer to the handler */
  59.         0,            /* reserved */
  60.         FUNCTION},        /* this is a handler, not a function */
  61.  
  62.     {    NULL,            /* NULLs signify the end of the table */
  63.         NULL,
  64.         0,
  65.         0}    };
  66.  
  67.